package com.yt.ds.chapter4;

/**
 * @Author: lzf
 * @Date: 2020/7/31 10:54
 * @Description: 有向图 顶点可达性
 */
public class TransitiveClosure {
    private DepthFirstSearch[] all;

    TransitiveClosure(Digraph digraph) {
        all = new DepthFirstSearch[digraph.getVertexNum()];
        for (int v = 0; v < digraph.getVertexNum(); v++) {
            all[v] = new DepthFirstSearch(digraph, v);
        }
    }

    /**
     * 描述：v 能否 达到 w
     *
     * @param v 顶点v
     * @param w 顶点w
     * @return "boolean"
     * @date: 2020/7/31 10:56
     */
    public boolean reachable(int v, int w) {
        return all[v].marked(w);
    }
}
